package com.gitee.wsl.mathematics.complex.quaternion.ext

import com.gitee.wsl.mathematics.coordinate.d3.Coordinate3
import com.gitee.wsl.mathematics.complex.quaternion.Quaternion

fun<T:Number> Quaternion<T, *>.multiplyFront(x: T, y: T, z: T, w: T ) = set(
    w * this.x + x * this.w + y * this.z - z * this.y,
    w * this.y - x * this.z + y * this.w + z * this.x,
    w * this.z + x * this.y - y * this.x + z * this.w,
    w * this.w - x * this.x - y * this.y - z * this.z
)

fun<T:Number> Quaternion<T, *>.multiplyFront(q: Quaternion<T, *>)= multiplyFront(q.x, q.y, q.z, q.w)

// multiplies by a pure quaternion of the given vector
fun<T:Number> Quaternion<T, *>.multiplyFront(v: Coordinate3<T, *>)= set(
    +v.x * w + v.y * z - v.z * y,
    -v.x * z + v.y * w + v.z * x,
    +v.x * y - v.y * x + v.z * w,
    -v.x * x - v.y * y - v.z * z
)

